package com.jy.modules.cims.component.common.service;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.data.common.dao.TCMmConstraintValueDao;
import com.jy.modules.cims.data.common.dto.TCMmConstraintValueDTO;
import com.jy.platform.core.common.BaseDTO;

/**
 * @classname: TCMmConstraintValueService
 * @description: 定义  T_C_MM_CONSTRAINT_VALUE 实现类
 * @author:  JY-IT-D001
 */
@Service("com.jy.modules.cims.component.common.service.TCMmConstraintValueService")
public class TCMmConstraintValueService implements Serializable {

    private static final long serialVersionUID = 1L;
    
	@Autowired
	private TCMmConstraintValueDao dao;

	/**
     * @author JY-IT-D001
     * @description: 分页查询 T_C_MM_CONSTRAINT_VALUE列表
     * @date 2015-01-06 17:32:39
     * @param searchParams 条件
     * @return
     * @throws
     */ 
	public List<TCMmConstraintValueDTO> searchTCMmConstraintValueByPaging(Map<String,Object> searchParams) throws Exception {
		List<TCMmConstraintValueDTO> dataList =  dao.searchTCMmConstraintValueByPaging(searchParams);
		return dataList;
	}
	/**
     * @author JY-IT-D001
     * @description: 按条件查询T_C_MM_CONSTRAINT_VALUE列表
     * @date 2015-01-06 17:32:39
     * @param searchParams 条件
     * @return
     * @throws
     */
	public List<TCMmConstraintValueDTO> searchTCMmConstraintValue(Map<String,Object> searchParams) throws Exception {
	    List<TCMmConstraintValueDTO> dataList = dao.searchTCMmConstraintValue(searchParams);
        return dataList;
    }
	/**
     * @author JY-IT-D001
     * @description: 查询T_C_MM_CONSTRAINT_VALUE对象
     * @date 2015-01-06 17:32:39
     * @param id
     * @return
     * @throws
     */ 
	public TCMmConstraintValueDTO queryTCMmConstraintValueByPrimaryKey(String id) throws Exception {
		
		TCMmConstraintValueDTO dto = dao.findTCMmConstraintValueByPrimaryKey(id);
		
		if(dto == null) dto = new TCMmConstraintValueDTO();
		
		return dto;
		
	}

	/**
     * @title: insertTCMmConstraintValue
     * @author JY-IT-D001
     * @description: 新增 T_C_MM_CONSTRAINT_VALUE对象
     * @date 2015-01-06 17:32:39
     * @param dto
     * @return
     * @throws
     */
	@SuppressWarnings("all")
	public Long insertTCMmConstraintValue(TCMmConstraintValueDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		int count = dao.insertTCMmConstraintValue(paramMap);
		
		TCMmConstraintValueDTO resultDto = (TCMmConstraintValueDTO) paramMap.get("dto");
		Long keyId = resultDto.getId();
		return keyId;
	}
	/**
     * @title: updateTCMmConstraintValue
     * @author JY-IT-D001
     * @description: 修改 T_C_MM_CONSTRAINT_VALUE对象
     * @date 2015-01-06 17:32:39
     * @param paramMap
     * @return
     * @throws
     */
	public void updateTCMmConstraintValue(TCMmConstraintValueDTO dto) throws Exception {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", dto);
		
		dao.updateTCMmConstraintValue(paramMap);
	}
	/**
     * @title: deleteTCMmConstraintValueByPrimaryKey
     * @author JY-IT-D001
     * @description: 删除 T_C_MM_CONSTRAINT_VALUE,按主键
     * @date 2015-01-06 17:32:39
     * @param paramMap
     * @throws
     */ 
	public void deleteTCMmConstraintValueByPrimaryKey(BaseDTO baseDto,String ids) throws Exception {
		if(StringUtils.isEmpty(ids)) throw new Exception("删除失败！传入的参数主键为null");
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("dto", baseDto);
		paramMap.put("ids", ids);
		dao.deleteTCMmConstraintValueByPrimaryKey(paramMap);
	}
	/**
	 * 批量操作
	 * @param list
	 */
	public void handleTCMmConstraintValue(List<HashMap<String,Object>> list,String constraintId){
		//先删除再新增
		HashMap<String,Object> paramMap=new HashMap<String,Object>();
		paramMap.put("ids", constraintId);
		dao.deleteTCMmConstraintValueByConstraintId(paramMap);
		if(list!=null&&!list.isEmpty()){
			for(HashMap<String,Object> dto:list){
				paramMap.clear();
				paramMap.put("dto", dto);
				dto.put("constraintId",constraintId);
				dao.insertTCMmConstraintValue(paramMap);
			}
		}
	}
}

